package cn.itcast.up.common.mytest

import com.typesafe.config.{Config, ConfigFactory}
import pureconfig.ConfigSource


//封装up.conf配置文件
case class UpHolder(
                     model: Model,
                     hadoop: Hadoop,
                     mysql: MySQL,
                     oozie: Oozie
                   )

case class Model(
                  user: String,
                  app: String,
                  path: Path
                )

case class Path(
                 jars: String,
                 modelBase: String
               )

case class Hadoop(
                   nameNode: String,
                   resourceManager: String
                 )

case class MySQL(
                  url: String,
                  driver: String,
                  tagTable: String,
                  modelTable: String
                )

case class Oozie(
                  url: String,
                  params: Map[String, String]
                )


object UpHolder {
  //导入隐式类型转换
  import pureconfig.generic.auto._

  //将up.conf配置文件中的数据加载到UpHolder对象中.
  private val config: Config = ConfigFactory.load("up")
  //将config对象转换为UpHolder
  private val upHolder: UpHolder = ConfigSource
    //从config中加载数据
    .fromConfig(config)
    //将数据装载为UpHolder
    .load[UpHolder]
    //获取正确的信息.left是失败的数据
    .right.get

  val model: Model = upHolder.model
  val hadoop: Hadoop = upHolder.hadoop
  val mysql: MySQL = upHolder.mysql
  val oozie: Oozie = upHolder.oozie


  def main(args: Array[String]): Unit = {
    println(UpHolder.model)
    println(UpHolder.hadoop)
    println(UpHolder.mysql)
    println(UpHolder.oozie)
  }


}